/*
 * Translated default messages for the jQuery validation plugin.
 * Locale: CN
 */
jQuery.extend(jQuery.validator.messages, {
        required: "必填字段",
		remote: "该值已存在",
		email: "请输入正确格式的电子邮件",
		url: "请输入合法的网址",
		date: "请输入合法的日期",
		dateISO: "请输入合法的日期 (ISO).",
		number: "请输入合法的数字",
		digits: "只能输入整数",
		creditcard: "请输入合法的信用卡号",
		equalTo: "请再次输入相同的值",
		accept: "请输入拥有合法后缀名的字符串",
		maxlength: jQuery.validator.format("输入长度最多是 {0} 个字符"),
		minlength: jQuery.validator.format("输入长度最少是 {0} 个字符"),
		rangelength: jQuery.validator.format("输入字符长度请介于 {0} 和 {1} 之间"),
		range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
		max: jQuery.validator.format("请输入一个最大为 {0} 的值"),
		min: jQuery.validator.format("请输入一个最小为 {0} 的值")
});

function remoteValidator(validator,link,msg,tp)
{
	$.validator.addMethod("remoteValidat",function(value,element,params){
			if ( validator.optional(element) )
				return "dependency-mismatch";
			
			var previous = validator.previousValue(element);
			if (!validator.settings.messages[element.name] )
				validator.settings.messages[element.name] = {};
			previous.originalMessage = validator.settings.messages[element.name].remote;
			validator.settings.messages[element.name].remote = previous.message;
				if ( previous.old !== value ) {
					previous.old = value;
					validator.startRequest(element);
					var p = prepareParams();
					$.ajax({
						   type: tp,
						   url: link,
						   data: p,
						   port: "validate" + element.name,
						   mode: "abort",
						   success: function(response){
							   var valid = response === 'true';
							   if(response == 'true'){
								   var submitted = validator.formSubmitted;
									validator.prepareElement(element);
									validator.formSubmitted = submitted;
									validator.successList.push(element);
									validator.showErrors();
							   } else {
									var errors = {};
									var message = msg;
									if(message == null)
										message = validator.defaultMessage( element, "remote" );
									errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
									validator.showErrors(errors);
								}
								previous.valid = valid;
								validator.stopRequest(element, valid);
						   }
						}); 
					return "pending";
				}else if( validator.pending[element.name] ) {
					return "pending";
				}
				return previous.valid;	
	},msg);
}